tetralat.panel.ligotera = function() {
	if (tetralat.rank <= 2) { tetralat.rank = tetralat.paleta.length; }
	else { tetralat.rank--; }
	tetralat.proetimasia();

	var req = new Request('tetralat/rank');
	var params = 'rank=' + uri(tetralat.rank);
	req.send(params);
};

tetralat.panel.neo = function() {
	tetralat.proetimasia();
};

tetralat.panel.perisotera = function() {
	if (tetralat.rank >= tetralat.paleta.length) { tetralat.rank = 2; }
	else { tetralat.rank++; }
	tetralat.proetimasia();

	var req = new Request('tetralat/rank');
	var params = 'rank=' + uri(tetralat.rank);
	req.send(params);
};

tetralat.panel.ipodixi = function(img) {
	tetralat.ipodixi = !tetralat.ipodixi;
	if (isSet(img)) {
		img.prevSrc = globals.server + 'images/panel/' + (tetralat.ipodixi ?
			'kripseIpodixi.png' : 'dixeIpodixi.png');
		img.parentNode.title = tetralat.ipodixi ? 'Hide hints' : 'Show hints';
	}
	if (tetralat.ipodixi) {
		tetralat.adinata.dixeOla();
	}
	else {
		tetralat.adinata.clearOla();
	}

	var req = new Request('tetralat/ipodixi');
	var params = 'ipodixi=' + (tetralat.ipodixi ? 'true' : 'false');
	req.send(params);
};

tetralat.panel.diamperes = function(img) {
	tetralat.diamperes = !tetralat.diamperes;
	var display = tetralat.diamperes ? 'none' : 'inline';
	for (var i = 0; i < tetralat.rank; i++) {
		for (var j = 0; j < tetralat.rank; j++) {
			var x = getelid('o:' + i + ':' + j);
			if (isSet(x)) { x.style.display = display; }
		}
	}

	if (isSet(img)) {
		img.prevSrc = globals.server + 'images/panel/' + (tetralat.diamperes ?
			'diamperesOff.png' : 'diamperesOn.png');
		img.parentNode.title = tetralat.diamperes ? 'Show canvas' : 'Hide canvas';
	}

	var req = new Request('tetralat/diamperes');
	var params = 'diamperes=' + (tetralat.diamperes ? 'true' : 'false');
	req.send(params);
};

tetralat.panel.paraskinioSwitch = function() {
	var istoriko = getelid('istoriko');
	if (notSet(istoriko)) { return; }

	if (!tetralat.istorikoSave(istoriko)) {
		tetralat.istorikoRestore(istoriko);
		return;
	}
	istoriko.innerHTML = '';

	for (var i = 0; i < globals.paraskinio.list.length; i++) {
		var b = document.createElement('img');
		if (notSet(b)) {
			tetralat.istorikoRestore(istoriko);
			return;
		}

		b.setAttribute('id', 'bthumb:' + i);
		b.setAttribute('class', (i == globals.paraskinio.index ?
			'paraskinioThumb paraskinioThumbCurrent' : 'paraskinioThumb'));
		b.setAttribute('src', globals.server + 'images/background/' +
			globals.paraskinio.list[i]);
		b.setAttribute('title', 'Click to change background pattern');
		b.style.width = tetralat.paraskinio.thumbWidth;
		b.style.height = b.style.width;
		eval('b.onmouseover = function() { tetralat.paraskinio.preview(' + i + '); };');
		eval('b.onmouseout = function() { tetralat.paraskinio.preview(' + i + ', true); };');
		eval("b.onclick = function() { tetralat.paraskinio.alagi(" + i + '); };');
		istoriko.appendChild(b);
	}
};

tetralat.paraskinio.preview = function(i, off) {
	if (i == globals.paraskinio.index) { return; }
	var bt = getelid('bthumb:' + i);
	if (notSet(bt)) { return; }

	if (isSet(off)) {
		bt.setAttribute('class', 'paraskinioThumb');
		document.body.style.backgroundImage =
			'url(' + globals.server + '/images/background/' +
			globals.paraskinio.list[globals.paraskinio.index] + ')';
	}
	else {
		bt.setAttribute('class', 'paraskinioThumb paraskinioThumbPreview');
		document.body.style.backgroundImage = 'url(' + bt.getAttribute('src') + ')';
	}
};

tetralat.paraskinio.alagi = function(index) {
	document.body.style.backgroundImage = 'url(' + globals.server +
		'images/background/' + globals.paraskinio.list[index] + ')';
	globals.paraskinio.index = index;
	tetralat.istorikoRestore();

	var req = new Request('tetralat/paraskinio');
	var params = 'paraskinio=' + uri(index);
	req.send(params);
};

tetralat.panel.bugFix = function() {
	for (var i = 0; i < tetralat.rank; i++) {
		for (var j = 0; j < tetralat.rank; j++) {
			tetralat.panel.ikopedoFix(i, j);
		}
	}

	for (var i = 0; i < tetralat.rank; i++) {
		for (var j = 0; j < tetralat.rank; j++) {
			tetralat.panel.odepokiFix(i, j);
		}
	}
	tetralat.dixeLathos();
	if (tetralat.ipodixi) {
		tetralat.adinata.dixeOla();
	}
};

tetralat.panel.ikopedoFix = function(grami, stili) {
	var ikopedo = getelid('i:' + grami + ':' + stili);
	if (notSet(ikopedo)) { return; }
	if (notSet(ikopedo.tetralat)) { return; }
	if (notSet(ikopedo.tetralat.sxetiko)) { return; }
	if (isSet(ikopedo.tetralat.sxetiko.tetralat) &&
		isSet(ikopedo.tetralat.sxetiko.tetralat.sxetiko) &&
		(ikopedo.tetralat.sxetiko.tetralat.sxetiko == ikopedo)) { return; }

	var tetragono = getelid('t:' + grami + ':' + stili);
	if (notSet(tetragono)) { return; }

	ikopedo.tetralat.sxetiko = null;
	tetragono.style.top = (ikopedo.tetralat.top + tetralat.dit) + 'px';
	tetragono.style.left = (ikopedo.tetralat.left + tetralat.dit) + 'px';
	ikopedo.setAttribute('class', ikopedo.tetralat['class']);
};

tetralat.panel.odepokiFix = function(grami, stili) {
	var odepoki = getelid('o:' + grami + ':' + stili);
	if (notSet(odepoki)) { return; }
	if (notSet(odepoki.tetralat)) { return; }
	if (notSet(odepoki.tetralat.sxetiko)) { return; }
	if (isSet(odepoki.tetralat.sxetiko.tetralat) &&
		isSet(odepoki.tetralat.sxetiko.tetralat.sxetiko) &&
		(odepoki.tetralat.sxetiko.tetralat.sxetiko == odepoki)) { return; }

	odepoki.tetralat.sxetiko = null;
};
